/*
 * Player
-color : int
+choosePawnToMove(index : int) : boolean
+movePawnToStart(pawn : int) : boolean
+move(pawn : int, positionToMove : int) : boolean
+getPawnAtPosition(boardIndex : int) : Pawn
+moveExists(cardValue : int) : boolean 
 */
public class Player 
{
    private int _color;
    private Pawn[] _pawn;
    
    /**
     * This is the Constructor method
     */
    public Player(int color)
    {
        // red = 0
        // blue = 1
        // yellow = 2
        // green = 3
        _color = color;
        
        _pawn = new Pawn[4];
        for (int i = 0; i < 4; i++)
        {
          _pawn[i] = new Pawn();
        }
    }
    
  /**
  *  Moves the given pawn to start
  */
  public void movePawnToStart(int pawnIndex) 
  {
    _pawn[pawnIndex].changeStart(true);
    _pawn[pawnIndex].move(-1);
  }
  
  public void move(int pawnIndex, int movement)
  {
      int index;
      int newIndex;
      
      if (_pawn[pawnIndex].getStart())
      {
          _pawn[pawnIndex].changeStart(false);
          _pawn[pawnIndex].move(4 + 15*_color);
      }
      else
      {
          index = _pawn[pawnIndex].getPositionIndex();
          newIndex = (index + movement)%60;
          _pawn[pawnIndex].move(newIndex);
          _pawn[pawnIndex].travel(movement);
      }
      
  }
  
  /*
  * Finds and returns which pawn is at the boardIndex given.
  * If no pawn exists in the given boardIndex then return -1.
  */
  public int getPawnAtPosition(int boardIndex)
  {
    int pawnIndex = -1;
    for(int i = 0; i < (_pawn.length - 1); i++)
    {
      if(_pawn[i].getPositionIndex() == boardIndex)
      {
        pawnIndex = i;
      }
    }
    
    return pawnIndex;
  }

  public int getPawnPosition(int pawnIndex)
  {
      return _pawn[pawnIndex].getPositionIndex();
  }
  
  public boolean getSafetyZone(int pawnIndex)
  {
      return _pawn[pawnIndex].getSZ();
  }

  public boolean getStart(int pawnIndex)
    {
      return _pawn[pawnIndex].getStart();
  }

  /*
  public boolean moveExists(int cardValue)
  {
    System.out.println("moveExists not developed yet");
  }
   * 
   */

  public int pawnsInHome()
  {
      int pawns = 0;
      for (int i = 0; i < 4; i++)
      {
          if (_pawn[i].getHome())
          {
              pawns++;
          }
      }
      return pawns;
  }

  public int pawnsInStart()
  {
      int pawns = 0;
      for (int i = 0; i < 4; i++)
      {
          if (_pawn[i].getStart())
          {
              pawns++;
          }
      }
      return pawns;
  }

    
}
